'use strict';
const Service = require('egg').Service;

class UserService extends Service {
    async getAll() {

        const users = await this.ctx.model.User.findAll();
        const projects = await this.ctx.model.Project.findAll();
        return users;
    }

    async createUser(obj) {
        const user = await this.ctx.model.User.createUser(obj);
        return 1;
    }

    async deleteUser(id) {
        const user = await this.ctx.model.User.deleteUser(id);
        return 1;
    }

    async updateUser(obj) {
        const user = await this.ctx.model.User.updateUser(obj);
        return 1;
    }
    async associate() {
        const users = await this.ctx.model.User.associate();
        return users;
    }

    async query() {

        var table = { id: 1 }
        const sql = `select a.id,a.name,a.sex  from  user a  LEFT JOIN project b on  a.id=b.user_id where a.id='${table.id}' `

        const users = await this.ctx.model.query(sql, { type: this.ctx.model.QueryTypes.SELECT });
        return users;
    }


}

module.exports = UserService;